// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.utils;

import java.io.Serializable;
import java.util.Arrays;

public class IntHypercube implements Serializable, Cloneable {
    private static final long serialVersionUID = 1L;
    private final int width;
    private final int height;
    private final int depth;
    private final int quanta;
    private final int wxh;
    private final int wxhxd;
    private final int[] value;

    public IntHypercube(int _width, int _height, int _depth, int _quanta) {
        this.width = _width;
        this.height = _height;
        this.depth = _depth;
        this.quanta = _quanta;
        this.wxh = _width * _height;
        this.wxhxd = this.wxh * _depth;
        this.value = new int[this.wxhxd * _quanta];
    }

    public IntHypercube clone() throws CloneNotSupportedException {
        IntHypercube intHypercube0 = new IntHypercube(this.width, this.height, this.depth, this.quanta);
        System.arraycopy(this.value, 0, intHypercube0.value, 0, this.value.length);
        return intHypercube0;
    }

    public void clear() {
        Arrays.fill(this.value, 0);
    }

    public void fill(int newValue) {
        Arrays.fill(this.value, newValue);
    }

    private int getIndex(int int2, int int3, int int1, int int0) {
        return int2 >= 0 && int3 >= 0 && int1 >= 0 && int0 >= 0 && int2 < this.width && int3 < this.height && int1 < this.depth && int0 < this.quanta
            ? int2 + int3 * this.width + int1 * this.wxh + int0 * this.wxhxd
            : -1;
    }

    public int getValue(int x, int y, int z, int w) {
        int _int = this.getIndex(x, y, z, w);
        return _int == -1 ? 0 : this.value[_int];
    }

    public void setValue(int x, int y, int z, int w, int newValue) {
        int _int = this.getIndex(x, y, z, w);
        if (_int != -1) {
            this.value[_int] = newValue;
        }
    }

    public final int getWidth() {
        return this.width;
    }

    public final int getHeight() {
        return this.height;
    }

    public final int getDepth() {
        return this.depth;
    }

    public final int getQuanta() {
        return this.quanta;
    }
}
